//
//  DetailView.m
//  2760
//
//  Created by 强 on 15/12/8.
//  Copyright (c) 2015年 杰润. All rights reserved.
//

#import "DetailView.h"

@implementation DetailView
+(instancetype)detailView {
    return [[self alloc] init];
}
- (void)willMoveToSuperview:(UIView *)newSuperview {
    self.backgroundColor = [UIColor redColor];
    self.frame = CGRectMake(0, 64,  [UIScreen mainScreen].bounds.size.width,  [UIScreen mainScreen].bounds.size.height);
//    self.frame =
    [self createTableview];
    [self createButton];
    
}
- (void)createButton {
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, 40,40 )];
    label.text =  @"详情";
    [ self  addSubview:label];
    
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(300, 0, 40, 40)];
    
    [button setTitle:@"关闭" forState:UIControlStateNormal];
    
    [self addSubview:button];
    
    [button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
    
}
- (void)createTableview {
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 44, self.bounds.size.width, self.bounds.size.height-44)];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self addSubview:self.tableView];
}

#pragma mark - 协议方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [[UITableViewCell alloc] init];
    cell.textLabel.text = @"12";
    return cell;
}
- (void)buttonAction {
    
    [self removeFromSuperview];
    self.frame = CGRectZero;
    self.tableView.frame = CGRectZero;
    [self.tableView removeFromSuperview];
}


@end
